package main

import (
	"fmt"
	"time"
)

func hello(done chan bool) {
	fmt.Println("hello world chan")
	done <- true
}

func add(sum chan int, a ...int)  {
	res := 0
	for _, v := range a {
		res += v
	}
	time.Sleep(1 * time.Second)
	fmt.Println("end execute add...")
	sum <- res
}

func multi(mul chan int, a ...int) {
	res := 1
	for _, v := range a {
		res *= v
	}
	fmt.Println("end execute multi...")
	mul <- res
}

func main() {
	done := make(chan bool)
	go hello(done)
	res := <-done
	fmt.Println("res", res)
	var sumC, mulC = make(chan int), make(chan int)
	fmt.Println("begin execute add...")
	go add(sumC, 1,2,3,4,5)
	go multi(mulC, 1,2,3,4,5)
	sum, mul := <-sumC, <-mulC
	fmt.Printf("%d + %d = %d\n",sum, mul, sum + mul)
	fmt.Println("main() end.")


}
